# 一开始想用双指针，发现不行
nums = [1,2,-1,-2,2,1,-2,1,4,-5,4]

def maxSubArray(nums) -> int:
    if len(nums) == 1:
        return nums[0]
    x = nums
    max = -2**32
    left ,right = 0, len(nums)-1
    while left <= right:
        _max = sum(x[left:right+1])
        if _max > max:
            max = _max
        if x[left] >= x[right]:
            right -= 1
        if x[left] < x[right]:
            left += 1
        
    return max

print(maxSubArray(nums))